/*
 * JavaZOOM : jlgui@javazoom.net http://www.javazoom.net
 * ----------------------------------------------------------------------- This
 * program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Library General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version. This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
 * General Public License for more details. You should have received a copy of
 * the GNU Library General Public License along with this program; if not, write
 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 * USA.----------------------------------------------------------------------
 */
package de.preamp.clients.java.player;

/**
 * This class implements player events. It is based on
 * javazoom.jlgui.basicplayer.BasicPlayerEvent
 * 
 * @author André Stannek
 * @since 2010-08-18
 * @version 2010-08-22
 */
public class PreampPlayerEvent
{
    /**
     * 
     */
    private final transient EventType code;

    /**
     * 
     */
    private final transient int position;

    /**
     * 
     */
    private final transient double value;

    /**
     * 
     */
    private final transient Object source;

    /**
     * 
     */
    private final transient Object description;

    /**
     * Constructor.
     * 
     * @param source
     *            of the event
     * @param code
     *            of the envent
     * @param position
     *            optional stream position
     * @param value
     *            opitional control value
     * @param desc
     *            optional description
     */
    public PreampPlayerEvent(final Object source, final EventType code,
	    final int position, final double value, final Object desc)
    {
	this.value = value;
	this.position = position;
	this.source = source;
	this.code = code;
	description = desc;
    }

    /**
     * Return code of the event triggered.
     * 
     * @return the PlayerState of this event
     */
    public final EventType getType()
    {
	return code;
    }

    /**
     * Return position in the stream when event occured.
     * 
     * @return the position in the stream when event occured
     */
    public final int getPosition()
    {
	return position;
    }

    /**
     * Return control value related to event triggered.
     * 
     * @return the control value related to event triggered
     */
    public final double getValue()
    {
	return value;
    }

    /**
     * Return description.
     * 
     * @return the description of the event
     */
    public final Object getDescription()
    {
	return description;
    }

    /**
     * @return the source of the event
     */
    public final Object getSource()
    {
	return source;
    }

    @Override
    public final String toString()
    {
	if (code.equals(EventType.OPENING))
	{
	    return "OPENING: " + position + ": " + description;
	}
	else if (code.equals(EventType.PAN) || code.equals(EventType.GAIN))
	{
	    return code.toString() + ": " + value;
	}
	else
	{
	    return code.toString() + ": " + position;
	}
    }
}
